#include "Queue.h"
void QueueInit(Queue* pq)
{
	assert(pq);
	pq->head = pq->tail = NULL;
	pq->size = 0;

}
void QueueDestory(Queue* pq)
{
	assert(pq);
	while (!QueueEmpty(pq))
	{
		QueuePop(pq);
	}
	

}
void QueuePush(Queue* pq, DataType x)
{
	assert(pq);
	QNode* newnode = malloc(sizeof(QNode));
	if (newnode == NULL)
	{
		perror("malloc fail");
		exit(-1);
	}
	newnode->data = x;
	newnode->next = NULL;
	if (pq->head == NULL)
	{
		pq->head = pq->tail = newnode;
	}
	else
	{
		pq->tail->next = newnode;
		pq->tail = newnode;
	}
	++pq->size;
}
void QueuePop(Queue* pq)
{
	assert(pq);
	assert(!QueueEmpty(pq));
	
	QNode* next = pq->head->next;
	free(pq->head);
	pq->head = next;
	if (pq->head == NULL)
	{
		pq->tail = NULL;
	}
	--pq->size;
}

DataType QueueFront(Queue* pq)
{
	return pq->head->data;
}
DataType QueueBack(Queue* pq)
{
	return pq->tail->data;
}

bool QueueEmpty(Queue* pq)
{
	return pq->head == NULL;
}
size_t QueueSize(Queue* pq)
{
	return pq->size;
}

